package org.bot.client.flow;

import lombok.Getter;
import lombok.Setter;
import org.bot.api.flow.FlowNode;

import java.util.UUID;

/**
 * @author 沧月
 * @create 0020 2023/10/20 09:27
 * @description <description class purpose>
 */

@Setter
@Getter
public class FlowTask implements Runnable {

    private FlowNode flowData;

    private String flowId;

    private boolean isDebug;

    private String clientId;

    private FlowExecute flowExecute;

    private String batchId;

    private Integer order = 0;

    private boolean interrupt = false;

    private String flowName;

    @Override
    public void run() {
        flowExecute.runTask(this);
    }

    public String getBatchId() {
        if (this.batchId == null) {
            this.batchId = UUID.randomUUID().toString().replaceAll("-", "");
        }
        return batchId;
    }

    public Integer getOrder() {
        order++;
        return this.order;
    }

    public void taskInterrupt() {
        if (this.interrupt) {
            throw new RuntimeException("任务强制终止");
        }
    }
}
